package com.example.score.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.score.entity.GradeInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GradeInfoMapper extends BaseMapper<GradeInfo> {
    // 现有的方法...
    
    @Insert("<script>" +
            "INSERT INTO t_grade_info (exam_detail_id, grade_id, grade_name, created_time, updated_time) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.examDetailId}, #{item.gradeId}, #{item.gradeName}, now(), now())" +
            "</foreach>" +
            "</script>")
    void insertBatch(@Param("list") List<GradeInfo> gradeInfos);

    @Select("select * from t_grade_info where grade_id =#{gradeId} ")
    List<GradeInfo> selectByGradeId(Long gradeId);

    @Select("<script>" +
            "select distinct  exam_detail_id as examDetailId ,grade_id as gradeId, grade_name gradeName from t_grade_info " +
            "where exam_detail_id in  " +
            "<foreach collection='allExamDetailIds' item='examDetailId' open='(' separator=',' close=')'>" +
            "#{examDetailId}" +
            "</foreach> </script>" )
    List<GradeInfo> selectByExamDetailIds(List<Long> allExamDetailIds);
}